<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>美食推荐 - 汉中旅游</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/meishi.css">
</head>
<body>
    <!-- 页面加载动画 -->
    <div class="page-loader">
        <div class="loader"></div>
    </div>

    <!-- 用户小部件 -->
    <div class="user-widget">
        <a href="login.html" id="login-link" class="btn btn-login">登录/注册</a>
        <div id="user-profile" style="display: none;">
            <img src="img/attractions/touxiang.jpg" alt="User Avatar" class="avatar">
            <span id="username-display"></span>
            <a href="#" id="logout-link" title="退出登录"><i class="fas fa-sign-out-alt"></i></a>
        </div>
    </div>

    <!-- 浮动导航菜单 -->
    <div class="float-nav">
        <button class="float-nav-toggle" id="floatNavToggle" title="快速导航">
            <i class="fas fa-bars"></i>
        </button>
        <div class="float-nav-menu" id="floatNavMenu">
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="jingdian.html">景点介绍</a></li>
                <li><a href="luxian.html">旅游线路</a></li>
                <li><a href="gonglue.html">旅游攻略</a></li>
                <li><a href="meishi.html" class="active">美食推荐</a></li>
                <li><a href="wenhua.html">汉文化活动</a></li>
                <li><a href="contact.html">联系我们</a></li>
                <li><a href="faq.html">常见问题</a></li>
            </ul>
        </div>
    </div>

    <!-- 导航栏 -->
    <nav>
        <div class="container">
            <div class="nav-container">
                <div class="nav-logo">
                    <a href="index.html">
                        <img src="img/attractions/logo.jpg" alt="汉中旅游" class="nav-logo-img">
                        <h2>汉中旅游</h2>
                    </a>
                </div>
                <ul class="main-nav">
                    <li><a href="index.html">首页</a></li>
                    <li><a href="jingdian.html">景点介绍</a></li>
                    <li><a href="luxian.html">旅游线路</a></li>
                    <li><a href="gonglue.html">旅游攻略</a></li>
                    <li><a href="meishi.html" class="active">美食推荐</a></li>
                    <li><a href="wenhua.html">汉文化活动</a></li>
                    <li><a href="contact.html">联系我们</a></li>
                    <li><a href="faq.html">常见问题</a></li>
                </ul>
                <!-- 用户操作区域已被移到独立的 user-widget 中 -->
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <main>
        <!-- 页面标题 -->
        <section class="page-header">
            <div class="container">
                <h1>汉中美食推荐</h1>
                <p>品味千年古城的独特美食文化</p>
            </div>
        </section>

        <!-- 美食展示区域 -->
        <section class="food-showcase">
            <div class="container">
                <div class="food-grid" id="food-grid-container">
                    <!-- 美食内容将由JS动态加载 -->
                    <p>正在加载美食数据...</p>
                </div>
            </div>
        </section>

        <!-- 店铺推荐区域 -->
        <section class="restaurant-section">
            <div class="container">
                <h2 class="section-title">美食名店推荐</h2>
                <div class="restaurant-grid" id="restaurant-grid-container">
                    <!-- 推荐店铺将由JS动态加载 -->
                    <p>正在加载推荐店铺...</p>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>关于我们</h3>
                    <p>汉中旅游网致力于为游客提供最全面的汉中旅游信息，让您的汉中之行更加便捷、愉快。</p>
                    <div class="social-links">
                        <a href="#"><i class="fab fa-weibo"></i></a>
                        <a href="#"><i class="fab fa-weixin"></i></a>
                        <a href="#"><i class="fab fa-qq"></i></a>
                    </div>
                </div>
                <div class="footer-section">
                    <h3>快速链接</h3>
                    <ul>
                        <li><a href="index.html">首页</a></li>
                        <li><a href="jingdian.html">景点介绍</a></li>
                        <li><a href="luxian.html">旅游线路</a></li>
                        <li><a href="gonglue.html">旅游攻略</a></li>
                        <li><a href="contact.html">联系我们</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>热门景点</h3>
                    <ul>
                        <li><a href="jingdian.html#wuhoumu">武侯墓</a></li>
                        <li><a href="jingdian.html#nanhu">南湖</a></li>
                        <li><a href="jingdian.html#dingjunshan">定军山</a></li>
                        <li><a href="jingdian.html#guchengqiang">古城墙</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>联系方式</h3>
                    <p><i class="fas fa-map-marker-alt"></i> 地址：陕西省汉中市</p>
                    <p><i class="fas fa-phone"></i> 电话：0916-123456</p>
                    <p><i class="fas fa-envelope"></i> 邮箱：info@hanzhong-tourism.com</p>
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="container">
                <p>&copy; 2023 汉中旅游网 版权所有</p>
            </div>
        </div>
    </footer>

    <script src="js/main.js"></script>
    <script src="js/script.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', async () => {
            renderAllFoods();
            renderAllRestaurants();
        });

        async function renderAllFoods() {
            const container = document.getElementById('food-grid-container');
            if (!container) return;

            try {
                const response = await fetch('http://localhost:8080/api/foods');
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                const foods = await response.json();

                if (!foods || foods.length === 0) {
                    container.innerHTML = '<p>暂无美食推荐。</p>';
                    return;
                }

                // 生成星级评分的HTML
                const getRatingStars = (rating) => {
                    let stars = '';
                    const fullStars = Math.floor(rating);
                    const halfStar = rating % 1 !== 0;
                    for (let i = 0; i < fullStars; i++) {
                        stars += '★';
                    }
                    if (halfStar) {
                        stars += '☆'; // 用空心星代表半星
                    }
                    return stars.padEnd(5, '☆');
                };
                
                // 生成标签的HTML
                const getTagsHtml = (tagsString) => {
                    if (!tagsString) return '';
                    return tagsString.split(',').map(tag => `<span class="food-tag">${tag.trim()}</span>`).join('');
                };

                const foodHtml = foods.map(food => `
                    <div class="food-item">
                        <div class="food-image">
                            <img src="${food.imageUrl || 'img/food/default.jpg'}" alt="${food.name}">
                        </div>
                        <div class="food-content">
                            <h3>${food.name}</h3>
                            <div class="food-tags">
                                ${getTagsHtml(food.tags)}
                            </div>
                            <p class="food-description">${food.description}</p>
                            <div class="food-features">
                                <div class="feature">
                                    <span class="feature-name">特色</span>
                                    <span class="feature-value">${food.specialFeature || '暂无'}</span>
                                </div>
                                <div class="feature">
                                    <span class="feature-name">价格</span>
                                    <span class="feature-value">¥${food.price || '暂无'}</span>
                                </div>
                                <div class="feature">
                                    <span class="feature-name">推荐指数</span>
                                    <span class="feature-value">${getRatingStars(food.rating)}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                `).join('');

                container.innerHTML = foodHtml;
            } catch (error) {
                console.error('获取美食数据失败:', error);
                container.innerHTML = '<p>加载美食数据失败，请稍后重试。</p>';
            }
        }

        async function renderAllRestaurants() {
            const container = document.getElementById('restaurant-grid-container');
            if (!container) return;

            try {
                const response = await fetch('http://localhost:8080/api/restaurants');
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                const restaurants = await response.json();

                if (!restaurants || restaurants.length === 0) {
                    container.innerHTML = '<p>暂无推荐店铺。</p>';
                    return;
                }
                
                const restaurantHtml = restaurants.map(res => `
                    <div class="restaurant-item">
                        <div class="restaurant-content">
                            <h3>${res.name}</h3>
                            <div class="restaurant-meta">
                                <span><i class="fas fa-map-marker-alt"></i> ${res.address || '暂无地址'}</span>
                                <span><i class="fas fa-star"></i> ${res.rating || '暂无评分'}分</span>
                            </div>
                            <p>${res.description}</p>
                            <div class="restaurant-info">
                                <p><strong>招牌菜：</strong> ${res.specialtyDish || '暂无'}</p>
                                <p><strong>价格：</strong> ${res.averagePrice || '暂无'}</p>
                                <p><strong>营业时间：</strong> ${res.openingHours || '暂无'}</p>
                                <p><strong>联系电话：</strong> ${res.phone || '暂无'}</p>
                            </div>
                        </div>
                    </div>
                `).join('');
                
                container.innerHTML = restaurantHtml;
            } catch (error) {
                console.error('获取餐厅数据失败:', error);
                container.innerHTML = '<p>加载餐厅数据失败，请稍后重试。</p>';
            }
        }
    </script>
    <style>
        /* 美食推荐页面特定样式 */
        .page-header {
            background-image: none;
            background-color: var(--primary-color);
        }
    </style>
</body>
</html> 